package com.SRMS.view;

/**
 * @author Albert
 * @version 1.0
 * @date 2023/12/21-21:10
 * @describe
 */


import com.SRMS.domain.*;
import com.SRMS.service.UserClientService;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.List;

public class StudyRoomManageView {
    private JFrame frame;
//    private StudentService studentService = new StudentService();
//    private AdministratorService administratorService = new AdministratorService();
    private UserClientService userClientService = new UserClientService();//用来登录服务器或者注册用户

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                e.printStackTrace();
            }
            new StudyRoomManageView().createAndShowGUI();
        });
    }

    /**
     * 创建GUI
     */
    private void createAndShowGUI() {
        frame = new JFrame("自习室管理系统");
        Image icon = Toolkit.getDefaultToolkit().getImage(System.getProperty("user.dir").replace("\\", "/") + "/SRMS.png");
        frame.setIconImage(icon);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 200);
        frame.setLocationRelativeTo(null);
        //在JFrame中增加相应关闭窗口的处理
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                //System.out.println("监听到关闭窗口了");
                userClientService.logout();
                //System.exit(0);
            }
        });
        createLoginPanel();

        frame.setVisible(true);
    }

    /**
     * 登录面板
     */
    private void createLoginPanel() {
        JPanel panel = new JPanel(new GridLayout(3, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        Font font = new Font("宋体", Font.BOLD, 16);
        JLabel usernameLabel = new JLabel("账号:");
        usernameLabel.setFont(font);
        JTextField usernameField = new JTextField();
        JLabel passwordLabel = new JLabel("密码:");
        passwordLabel.setFont(font);
        JPasswordField passwordField = new JPasswordField();

        JButton loginButton = new JButton("登录");
        loginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //检测网络是否畅通
                boolean netStatus = userClientService.ping("www.baidu.com");
                if(!netStatus){
                    JOptionPane.showMessageDialog(frame, "未连接到Internet，请检查网络连接！", "错误-未连接到Internet", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                // 在这里验证用户名和密码，如果成功则显示菜单页面
                int user = userClientService.authenticate(usernameField.getText(), new String(passwordField.getPassword()));
                //int user = authenticate("2122006666", "233333");//测试管理员界面用的
                //int user = authenticate("3121005362", "666666");//测试学生界面用的
                //user = 0;//测试界面用
                if (user != 2) {
                    frame.getContentPane().removeAll();
                    if (user == 0) {
                        studentPanel();
                    } else {
                        administratorPanel();
                    }
                    frame.setBounds(600, 250, 800, 400);
                    frame.revalidate();
                    frame.repaint();
                } else {
                    JOptionPane.showMessageDialog(frame, "登录失败，请检查用户名和密码", "错误", JOptionPane.ERROR_MESSAGE);
                }
            }
        });

        panel.add(usernameLabel);
        panel.add(usernameField);
        panel.add(passwordLabel);
        panel.add(passwordField);
        panel.add(new JLabel());
        panel.add(loginButton);

        frame.add(panel);
    }

    /**
     * 学生登录成功后看到的面板
     *
     * @return
     */
    private JPanel studentPanel() {
        JPanel panel = new JPanel(new GridLayout(3, 1, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JButton function1Button = new JButton("查询空闲自习室");
        JButton function2Button = new JButton("申请自习室");
        JButton function3Button = new JButton("查询申请到的自习室");
        JButton function4Button = new JButton("归还自习室使用权");
        JButton function5Button = new JButton("查询历史使用记录");

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(listAllStudyRoom());
                frame.revalidate();
            }
        });
        function2Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(applyStudyRoom());
                frame.revalidate();
            }
        });
        function3Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(UserClientService.getAppliedStudyRoom() == null){
                    JOptionPane.showMessageDialog(frame,"当前您还未申请到自习室，请成功申请自习室后再查看申请到的自习室信息！", "提示", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }
                frame.setContentPane(appliedStudyRoom());
                frame.revalidate();
            }
        });
        function4Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if(UserClientService.getAppliedStudyRoom() == null){
                    JOptionPane.showMessageDialog(frame,"当前您还未申请到自习室！", "提示", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }
                frame.setContentPane(returnRight());
                frame.revalidate();
            }
        });
        function5Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(historyUsage());
                frame.revalidate();
            }
        });

        //把按钮加入面板
        panel.add(function1Button);
        panel.add(function2Button);
        panel.add(function3Button);
        panel.add(function4Button);
        panel.add(function5Button);

        frame.add(panel);
        return panel;
    }

    /**
     * 登录成功后管理员看到的面板
     *
     * @return
     */
    private JPanel administratorPanel() {
        JPanel panel = new JPanel(new GridLayout(3, 1, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JButton function1Button = new JButton("查看使用权");
        JButton function2Button = new JButton("撤销使用权");
        JButton function3Button = new JButton("查看撤销记录");
        JButton function4Button = new JButton("添加学生");
        JButton function5Button = new JButton("更新学生");
        JButton function6Button = new JButton("删除学生");
        JButton function7Button = new JButton("查看所有学生");
        JButton function8Button = new JButton("添加自习室");
        JButton function9Button = new JButton("更新自习室");
        JButton function10Button = new JButton("删除自习室");
        JButton function11Button = new JButton("查看所有自习室");
        JButton function12Button = new JButton("查看自习室历史使用记录");

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(listRight());
                frame.revalidate();
            }
        });
        function2Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(revokeRight());
                frame.revalidate();
            }
        });
        function3Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(listRevokeRecord());
                frame.revalidate();
            }
        });
        function4Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(addStudent());
                frame.revalidate();
            }
        });
        function5Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studentId = JOptionPane.showInputDialog(frame,"请输入需要修改的学生的学号\n","修改学生信息",JOptionPane.PLAIN_MESSAGE);
                if(studentId == null){
                    return;
                }
                if(studentId.isEmpty()){
                    return;
                }
                Student student = UserClientService.getStudentById(studentId);
                if(student == null){
                    //System.out.println(">> 该学生并不存在！");
                    JOptionPane.showMessageDialog(frame, "该学生并不存在！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                frame.setContentPane(updateStudent(student));
                frame.revalidate();
            }
        });
        function6Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(deleteStudent());
                frame.revalidate();
            }
        });
        function7Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(listAllStudent());
                frame.revalidate();
            }
        });
        function8Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(addStudyRoom());
                frame.revalidate();
            }
        });
        function9Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studyRoomId = JOptionPane.showInputDialog(frame,"请输入需要修改的自习室的编号\n","修改自习室信息",JOptionPane.PLAIN_MESSAGE);
                if(studyRoomId == null){
                    return;
                }
                if(studyRoomId.isEmpty()){
                    return;
                }
                StudyRoom studyRoom = UserClientService.getStudyRoomById(studyRoomId);
                if(studyRoom == null){
                    //System.out.println(">> 该自习室并不存在！");
                    JOptionPane.showMessageDialog(frame, "该自习室并不存在！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(updateStudyRoom(studyRoom));
                frame.revalidate();
            }
        });
        function10Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(deleteStudyRoom());
                frame.revalidate();
            }
        });
        function11Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(listStudyRoom());
                frame.revalidate();
            }
        });
        function12Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                frame.setContentPane(listHistoryUsage());
                frame.revalidate();
            }
        });

        //把按钮加入面板
        panel.add(function1Button);
        panel.add(function2Button);
        panel.add(function3Button);
        panel.add(function4Button);
        panel.add(function5Button);
        panel.add(function6Button);
        panel.add(function7Button);
        panel.add(function8Button);
        panel.add(function9Button);
        panel.add(function10Button);
        panel.add(function11Button);
        panel.add(function12Button);

        frame.add(panel);
        frame.setSize(800, 400);
        return panel;
    }

    /**
     * 管理员点击查看自习室时显示的面板
     *
     * @return
     */
    private JPanel listStudyRoom() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        StudyRoomForAdministratorTableModel studyRoomForAdministratorTableModel = new StudyRoomForAdministratorTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                         查看所有自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(studyRoomForAdministratorTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.add(panel);
        return panel;
    }

    /**
     * 管理员点击‘查看自习室历史使用记录’时显示的面板
     *
     * @return
     */
    private JPanel listHistoryUsage() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        HistoryOfRoomUsageTableModel historyOfRoomUsageTableModel = new HistoryOfRoomUsageTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                       查看自习室历史使用记录");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(historyOfRoomUsageTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);
        // 设置列宽度
        jTable.getColumnModel().getColumn(0).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(1).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(2).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(3).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(4).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(5).setPreferredWidth(100);
        jTable.getColumnModel().getColumn(6).setPreferredWidth(100);


        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.setSize(800, 400);
        frame.add(panel);
        return panel;
    }

    /**
     * 管理员点击‘删除自习室’时显示的面板
     *
     * @return
     */
    private JPanel deleteStudyRoom() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(2, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JLabel studyRoomLabel = new JLabel("     自习室编号:");
        studyRoomLabel.setFont(new Font("宋体", Font.BOLD, 16));
        JTextField jTextField = new JTextField();
        JButton confirmButton = new JButton("删除");

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                删除自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studyRoomId = jTextField.getText();
                StudyRoom studyRoom = UserClientService.getStudyRoomById(studyRoomId);
                if(studyRoom == null){
                    //System.out.println(">> 该自习室并不存在！");
                    JOptionPane.showMessageDialog(frame, "该自习室并不存在！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int option = JOptionPane.showConfirmDialog(frame, "这将会删除所有与该自习室有关的记录，包括历史使用记录、学生拥有的使用权等。\n是否删除自习室编号为[ " + studyRoomId + " ]的自习室?", "确认",
                        JOptionPane.YES_NO_CANCEL_OPTION);

                if (option == JOptionPane.YES_OPTION) {
                    //System.out.println("确认删除");
                    if (UserClientService.deleteStudyRoomById(studyRoomId)) {
                        //System.out.println(">> 删除成功！");
                        JOptionPane.showMessageDialog(frame, "您已经成功删除自习室编号为[ " + studyRoomId + " ]的自习室！", "删除成功", JOptionPane.PLAIN_MESSAGE);

                    } else {
                        //System.out.println(">> 删除失败！");
                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功删除自习室编号为[ " + studyRoomId + " ]的自习室。", "删除失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否");
                }

            }
        });

        //添加到面板上
        panel2.add(studyRoomLabel);
        panel2.add(jTextField);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(500, 250);
        return panel;
    }

    /**
     * 管理员点击‘更新自习室’时显示的面板
     *
     * @return
     */
    private JPanel updateStudyRoom(StudyRoom studyRoom) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(5, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        Font font = new Font("宋体", Font.BOLD, 14);
        JLabel studentIdLabel = new JLabel("          自习室编号:");
        studentIdLabel.setFont(font);
        JLabel id = new JLabel(studyRoom.getStudyRoomId());
        id.setFont(new Font("宋体", Font.BOLD, 16));
        JLabel studentNameLabel = new JLabel("          自习室地址:");
        studentNameLabel.setFont(font);
        JTextField jTextField2 = new JTextField();
        jTextField2.setText(studyRoom.getAddress());
        JLabel passwordLabel = new JLabel("          自习室名字:");
        passwordLabel.setFont(font);
        JTextField jTextField3 = new JTextField();
        jTextField3.setText(studyRoom.getRoomName());
        JLabel majorLabel = new JLabel("          总座位数:");
        majorLabel.setFont(font);
        JTextField jTextField4 = new JTextField();
        String seats = studyRoom.getSeats() + "";
        jTextField4.setText(seats);

        JButton confirmButton = new JButton("修改");
        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("               修改自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                int seats = 0;
                try {
                    seats = Integer.parseInt(jTextField4.getText());//获取总座位数
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(frame, "总座位数输入错误，请重新输入正确的数字！", "错误", JOptionPane.ERROR_MESSAGE);
                }
                int students = studyRoom.getSeats() - studyRoom.getRemainingSeats();//计算该自习室使用人数
                if(students > seats){
                    JOptionPane.showMessageDialog(frame, "自习室总座位数不可低于自习室当前使用人数！当前使用人数为：[ " + students + " ]位学生", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studyRoomId = studyRoom.getStudyRoomId();
                String address = jTextField2.getText();
                String roomName = jTextField3.getText();
                int option = JOptionPane.showConfirmDialog(frame, "请确认所需要修改的自习室信息是否无误：\n  自习室编号 = " +
                        studyRoomId + "\n  自习室地址 = " + address + "\n  自习室名字 = " + roomName + "\n  总座位数 = " +
                        seats + "\n  剩余座位数 = " + (seats - students), "确认", JOptionPane.YES_NO_CANCEL_OPTION);

                //创新StudyRoom对象存放需要修改的自习室信息
                studyRoom.setStudyRoomId(studyRoomId);
                studyRoom.setAddress(address);
                studyRoom.setRoomName(roomName);
                studyRoom.setSeats(seats);
                studyRoom.setRemainingSeats(seats - students);

                if (option == JOptionPane.YES_OPTION) {

                    if (UserClientService.updateStudyRoom(studyRoom)) {

                        JOptionPane.showMessageDialog(frame, "您已经成功修改自习室编号为[ " + studyRoomId + " ]的自习室！", "修改成功", JOptionPane.PLAIN_MESSAGE);

                    } else {

                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功修改自习室编号为[ " + studyRoomId + " ]的自习室。", "修改失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否");
                }

            }
        });

        //添加到面板上
        panel2.add(studentIdLabel);
        panel2.add(id);
        panel2.add(studentNameLabel);
        panel2.add(jTextField2);
        panel2.add(passwordLabel);
        panel2.add(jTextField3);
        panel2.add(majorLabel);
        panel2.add(jTextField4);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(500, 500);
        return panel;
    }

    /**
     * 管理员点击‘添加自习室’时显示的面板
     *
     * @return
     */
    private JPanel addStudyRoom() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(5, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JLabel studyRoomIdLabel = new JLabel("          自习室编号:");
        studyRoomIdLabel.setFont(new Font("宋体", Font.BOLD, 16));
        JTextField jTextField = new JTextField();
        JLabel addressLabel = new JLabel("          自习室地址:");
        addressLabel.setFont(new Font("宋体", Font.BOLD, 16));
        JTextField jTextField2 = new JTextField();
        JLabel roomNameLabel = new JLabel("          自习室名字:");
        roomNameLabel.setFont(new Font("宋体", Font.BOLD, 16));
        JTextField jTextField3 = new JTextField();
        JLabel seatsLabel = new JLabel("          总座位数:");
        seatsLabel.setFont(new Font("宋体", Font.BOLD, 16));
        JTextField jTextField4 = new JTextField();

        JButton confirmButton = new JButton("添加");
        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                    添加自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studyRoomId = jTextField.getText();
                StudyRoom studyRoom = UserClientService.getStudyRoomById(studyRoomId);
                if(studyRoom != null){
                    JOptionPane.showMessageDialog(frame, "该自习室已经存在！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                int seats = 0;
                try {
                    seats = Integer.parseInt(jTextField4.getText());//获取总座位数
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(frame, "总座位数输入错误，请重新输入正确的数字！", "错误", JOptionPane.ERROR_MESSAGE);
                }
                String address = jTextField2.getText();
                String roomName = jTextField3.getText();
                int option = JOptionPane.showConfirmDialog(frame, "请确认所需要添加的自习室信息是否无误：\n  自习室编号 = " +
                                studyRoomId + "\n  自习室地址 = " + address + "\n  自习室名字 = " + roomName + "\n  总座位数 = " +
                                seats, "确认", JOptionPane.YES_NO_CANCEL_OPTION);

                //创新StudyRoom对象存放需要添加的自习室信息
                studyRoom = new StudyRoom();
                studyRoom.setStudyRoomId(studyRoomId);
                studyRoom.setAddress(address);
                studyRoom.setRoomName(roomName);
                studyRoom.setSeats(seats);
                studyRoom.setRemainingSeats(seats);

                if (option == JOptionPane.YES_OPTION) {

                    if (UserClientService.addStudyRoom(studyRoom)) {

                        JOptionPane.showMessageDialog(frame, "您已经成功添加自习室编号为[ " + studyRoomId + " ]的自习室！", "添加成功", JOptionPane.PLAIN_MESSAGE);

                    } else {

                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功添加自习室编号为[ " + studyRoomId + " ]的自习室。", "添加失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否");
                }

            }
        });

        //添加到面板上
        panel2.add(studyRoomIdLabel);
        panel2.add(jTextField);
        panel2.add(addressLabel);
        panel2.add(jTextField2);
        panel2.add(roomNameLabel);
        panel2.add(jTextField3);
        panel2.add(seatsLabel);
        panel2.add(jTextField4);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(600, 400);
        return panel;
    }

    /**
     * 管理员点击‘查看所有学生’时显示的面板
     *
     * @return
     */
    private JPanel listAllStudent() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        StudentTableModel studentTableModel = new StudentTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                           查看所有学生");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(studentTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);
        // 设置列宽度
        jTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable.getColumnModel().getColumn(1).setPreferredWidth(40);
        jTable.getColumnModel().getColumn(2).setPreferredWidth(160);
        jTable.getColumnModel().getColumn(3).setPreferredWidth(60);
        jTable.getColumnModel().getColumn(4).setPreferredWidth(15);
        jTable.getColumnModel().getColumn(5).setPreferredWidth(15);
        jTable.getColumnModel().getColumn(6).setPreferredWidth(55);


        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.setSize(800, 400);
        frame.add(panel);
        return panel;
    }

    /**
     * 管理员点击‘删除学生’时显示的面板
     *
     * @return
     */
    private JPanel deleteStudent() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(2, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JLabel studentIdLabel = new JLabel("     学号:");
        studentIdLabel.setFont(new Font("宋体", Font.BOLD, 16));
        JTextField jTextField = new JTextField();
        JButton confirmButton = new JButton("删除");

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("             删除学生");
        label.setFont(new Font("宋体", Font.BOLD, 18));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studentId = jTextField.getText();
                Student student = UserClientService.getStudentById(studentId);
                if(student == null){
                    //System.out.println(">> 该学生并不存在！");
                    JOptionPane.showMessageDialog(frame, "该学生并不存在！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int option = JOptionPane.showConfirmDialog(frame, "这将会删除所有与该学生有关的记录，包括历史使用记录、其拥有的使用权等。\n是否删除学号为[ " + studentId + " ]的学生?", "确认",
                        JOptionPane.YES_NO_CANCEL_OPTION);

                if (option == JOptionPane.YES_OPTION) {
                    //System.out.println("确认添加");
                    if (UserClientService.deleteStudentById(studentId)) {
                        //System.out.println(">> 申请成功！");
                        JOptionPane.showMessageDialog(frame, "您已经成功删除学号为[ " + studentId + " ]的学生！", "删除成功", JOptionPane.PLAIN_MESSAGE);

                    } else {
                        //System.out.println(">> 申请失败！");
                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功删除学号为[ " + studentId + " ]的学生。", "删除失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消添加");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭添加");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否添加");
                }

            }
        });

        //添加到面板上
        panel2.add(studentIdLabel);
        panel2.add(jTextField);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(400, 200);
        return panel;
    }

    /**
     * 管理员点击‘更新学生’时显示的面板
     * @param student 学生对象
     * @return
     */
    private JPanel updateStudent(Student student) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(8, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        Font font = new Font("宋体", Font.BOLD, 14);
        JLabel studentIdLabel = new JLabel("          学号:");
        studentIdLabel.setFont(font);
        JLabel id = new JLabel(student.getStudentId());
        id.setFont(new Font("宋体", Font.BOLD, 16));
        JLabel studentNameLabel = new JLabel("          姓名:");
        studentNameLabel.setFont(font);
        JTextField jTextField2 = new JTextField();
        jTextField2.setText(student.getStudentName());
        JLabel passwordLabel = new JLabel("          密码:");
        passwordLabel.setFont(font);
        JTextField jTextField3 = new JTextField();
        JLabel majorLabel = new JLabel("          专业:");
        majorLabel.setFont(font);
        JTextField jTextField4 = new JTextField();
        jTextField4.setText(student.getMajor());
        JLabel genderLabel = new JLabel("          性别:");
        genderLabel.setFont(font);
        JTextField jTextField5 = new JTextField();
        jTextField5.setText(student.getGender());
        JLabel ageLabel = new JLabel("          年龄:");
        ageLabel.setFont(font);
        JTextField jTextField6 = new JTextField();
        jTextField6.setText(student.getAge());
        JLabel telephoneLabel = new JLabel("          电话:");
        telephoneLabel.setFont(font);
        JTextField jTextField7 = new JTextField();
        jTextField7.setText(student.getTelephone());

        JButton confirmButton = new JButton("修改");
        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("             修改学生");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String gender = jTextField5.getText();
                if(!(gender.equals("男") || gender.equals("女"))){
                    JOptionPane.showMessageDialog(frame, "请输入正确的性别（男/女）！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                String studentName = jTextField2.getText();
                String password = jTextField3.getText();
                String major = jTextField4.getText();
                String age = jTextField6.getText();
                String telephone = jTextField7.getText();

                int option = JOptionPane.showConfirmDialog(frame, "请确认所需要修改的学生信息是否无误：\n  学号 = " +
                                student.getStudentId() + "\n  姓名 = " + studentName + "\n  密码 = " + password + "\n  专业 = " +
                                major + "\n  性别 = " + gender + "\n  年龄 = " + age + "\n  电话 = " + telephone,
                        "确认", JOptionPane.YES_NO_CANCEL_OPTION);

                //创新Student对象存放需要添加的学生信息
                student.setStudentName(studentName);
                student.setPassword(password);
                student.setAge(age);
                student.setGender(gender);
                student.setMajor(major);
                student.setTelephone(telephone);

                if (option == JOptionPane.YES_OPTION) {

                    if (UserClientService.updateStudent(student)) {

                        JOptionPane.showMessageDialog(frame, "您已经成功修改学号为[ " + student.getStudentId() + " ]的学生！", "添加成功", JOptionPane.PLAIN_MESSAGE);

                    } else {

                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功修改学号为[ " + student.getStudentId() + " ]的学生。", "添加失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否");
                }

            }
        });

        //添加到面板上
        panel2.add(studentIdLabel);
        panel2.add(id);
        panel2.add(studentNameLabel);
        panel2.add(jTextField2);
        panel2.add(passwordLabel);
        panel2.add(jTextField3);
        panel2.add(majorLabel);
        panel2.add(jTextField4);
        panel2.add(genderLabel);
        panel2.add(jTextField5);
        panel2.add(ageLabel);
        panel2.add(jTextField6);
        panel2.add(telephoneLabel);
        panel2.add(jTextField7);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(400, 500);
        return panel;
    }

    /**
     * 管理员点击‘添加学生’时显示的面板
     *
     * @return
     */
    private JPanel addStudent() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(8, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        Font font = new Font("宋体", Font.BOLD, 14);
        JLabel studentIdLabel = new JLabel("          学号:");
        studentIdLabel.setFont(font);
        JTextField jTextField = new JTextField();
        JLabel studentNameLabel = new JLabel("          姓名:");
        studentNameLabel.setFont(font);
        JTextField jTextField2 = new JTextField();
        JLabel passwordLabel = new JLabel("          密码:");
        passwordLabel.setFont(font);
        JTextField jTextField3 = new JTextField();
        JLabel majorLabel = new JLabel("          专业:");
        majorLabel.setFont(font);
        JTextField jTextField4 = new JTextField();
        JLabel genderLabel = new JLabel("          性别:");
        genderLabel.setFont(font);
        JTextField jTextField5 = new JTextField();
        JLabel ageLabel = new JLabel("          年龄:");
        ageLabel.setFont(font);
        JTextField jTextField6 = new JTextField();
        JLabel telephoneLabel = new JLabel("          电话:");
        telephoneLabel.setFont(font);
        JTextField jTextField7 = new JTextField();

        JButton confirmButton = new JButton("添加");
        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("               添加学生");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studentId = jTextField.getText();
                Student student = UserClientService.getStudentById(studentId);
                if(student != null){
                    //System.out.println(">> 该学生已经存在！");
                    JOptionPane.showMessageDialog(frame, "该学生已经存在！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String gender = jTextField5.getText();
                if(!(gender.equals("男") || gender.equals("女"))){
                    JOptionPane.showMessageDialog(frame, "请输入正确的性别（男/女）！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studentName = jTextField2.getText();
                String password = jTextField3.getText();
                String major = jTextField4.getText();
                String age = jTextField6.getText();
                String telephone = jTextField7.getText();
                int option = JOptionPane.showConfirmDialog(frame, "请确认所需要添加的学生信息是否无误：\n  学号 = " +
                                studentId + "\n  姓名 = " + studentName + "\n  密码 = " + password + "\n  专业 = " +
                                major + "\n  性别 = " + gender + "\n  年龄 = " + age + "\n  电话 = " + telephone,
                        "确认", JOptionPane.YES_NO_CANCEL_OPTION);

                //创新Student对象存放需要添加的学生信息
                student = new Student();
                student.setStudentId(studentId);
                student.setStudentName(studentName);
                student.setPassword(password);
                student.setAge(age);
                student.setGender(gender);
                student.setMajor(major);
                student.setTelephone(telephone);

                if (option == JOptionPane.YES_OPTION) {

                    if (UserClientService.addStudent(student)) {

                        JOptionPane.showMessageDialog(frame, "您已经成功添加学号为[ " + studentId + " ]的学生！", "添加成功", JOptionPane.PLAIN_MESSAGE);

                    } else {

                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功添加学号为[ " + studentId + " ]的学生。", "添加失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否");
                }

            }
        });

        //添加到面板上
        panel2.add(studentIdLabel);
        panel2.add(jTextField);
        panel2.add(studentNameLabel);
        panel2.add(jTextField2);
        panel2.add(passwordLabel);
        panel2.add(jTextField3);
        panel2.add(majorLabel);
        panel2.add(jTextField4);
        panel2.add(genderLabel);
        panel2.add(jTextField5);
        panel2.add(ageLabel);
        panel2.add(jTextField6);
        panel2.add(telephoneLabel);
        panel2.add(jTextField7);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(450, 550);
        return panel;
    }

    /**
     * 管理员点击‘查看撤销记录’时显示的面板
     *
     * @return
     */
    private JPanel listRevokeRecord() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        RevokeRecordForAdminTableModel revokeRecordForAdminTableModel = new RevokeRecordForAdminTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                                            查看撤销记录");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(revokeRecordForAdminTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);
        // 设置列宽度
        jTable.getColumnModel().getColumn(0).setPreferredWidth(100);
        jTable.getColumnModel().getColumn(1).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(2).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(3).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(4).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(5).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(6).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(7).setPreferredWidth(55);
        jTable.getColumnModel().getColumn(8).setPreferredWidth(100);
        jTable.getColumnModel().getColumn(9).setPreferredWidth(225);

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.setSize(1250, 400);
        frame.add(panel);
        return panel;
    }

    /**
     * 管理员点击‘撤销使用权’时显示的面板
     *
     * @return
     */
    private JPanel revokeRight() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(3, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JLabel studentIdLabel = new JLabel("     想要撤销其使用权的学生的学号:");
        studentIdLabel.setFont(new Font("宋体", Font.BOLD, 14));
        JTextField jTextField = new JTextField();
        JLabel revokeReasonLabel = new JLabel("     撤销原因:");
        revokeReasonLabel.setFont(new Font("宋体", Font.BOLD, 14));
        JTextField jTextField2 = new JTextField();
        JButton confirmButton = new JButton("撤销");

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                     撤销使用权");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studentId = jTextField.getText();
                RightToUseStudyRoom rightToUseStudyRoom = UserClientService.getRightByStuIdForAdministrator(studentId);
                if (rightToUseStudyRoom == null) {
                    JOptionPane.showMessageDialog(frame, "该学生并没有申请到自习室！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String revokeReason = jTextField2.getText();
                int option = JOptionPane.showConfirmDialog(frame, "是否确认撤销学号为[ " + studentId + " ]的学生的自习室使用权?", "确认",
                        JOptionPane.YES_NO_CANCEL_OPTION);

                if (option == JOptionPane.YES_OPTION) {

                    if (UserClientService.revokeRightByStudentId(studentId, revokeReason)) {

                        JOptionPane.showMessageDialog(frame, "您已经成功撤销学号为[ " + studentId + " ]的学生的自习室使用权！", "撤销成功", JOptionPane.PLAIN_MESSAGE);

                    } else {

                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功撤销学号为[ " + studentId + " ]的学生的自习室使用权。", "撤销失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消添加");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭添加");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否添加");
                }

            }
        });

        //添加到面板上
        panel2.add(studentIdLabel);
        panel2.add(jTextField);
        panel2.add(revokeReasonLabel);
        panel2.add(jTextField2);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(650, 250);
        return panel;
    }

    /**
     * 管理员点击‘查看使用权’时显示的面板
     *
     * @return
     */
    private JPanel listRight() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        RightRecordTableModel rightRecordTableModel = new RightRecordTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                           查看使用权");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(rightRecordTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);

        // 设置列宽度
        jTable.getColumnModel().getColumn(0).setPreferredWidth(80);
        jTable.getColumnModel().getColumn(1).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(2).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(3).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(4).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(5).setPreferredWidth(50);
        jTable.getColumnModel().getColumn(6).setPreferredWidth(100);

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(administratorPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.setSize(800, 400);
        frame.add(panel);
        return panel;
    }

    /**
     * 学生点击‘查询历史使用记录’时显示的面板
     *
     * @return
     */
    private JPanel historyUsage() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        HistoryForStudentTableModel historyForStudentTableModel = new HistoryForStudentTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                                 查询历史使用记录");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(historyForStudentTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(studentPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.setSize(1000, 400);
        frame.add(panel);
        return panel;
    }

    /**
     * 学生点击‘归还自习室使用权自习室’时显示的面板
     *
     * @return
     */
    private JPanel returnRight() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(2, 1, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        RoomForStudentTableModel roomForStudentTableModel = new RoomForStudentTableModel();
        JTable jTable = new JTable(roomForStudentTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);
        JButton confirmButton = new JButton("归还");

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                          归还自习室使用权");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(studentPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                int option = JOptionPane.showConfirmDialog(frame, "是否确认归还申请到的自习室?", "确认",
                        JOptionPane.YES_NO_CANCEL_OPTION);

                if (option == JOptionPane.YES_OPTION) {

                    RightToUseStudyRoom rightToUseStudyRoom = UserClientService.getRightByStuIdForStudent();
                    if (UserClientService.returnRight(rightToUseStudyRoom)) {

                        JOptionPane.showMessageDialog(frame, "您已经成功归还申请到的自习室！", "归还成功", JOptionPane.PLAIN_MESSAGE);

                    } else {

                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功归还申请到的自习室。", "归还失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消添加");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭添加");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否添加");
                }

            }
        });

        //添加到面板上
        panel2.add(jScrollPane);
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(800, 400);
        return panel;
    }

    /**
     * 学生点击‘查询申请到的自习室’时显示的面板
     *
     * @return
     */
    private JPanel appliedStudyRoom() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));


        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                          查询申请到的自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        RoomForStudentTableModel roomForStudentTableModel = new RoomForStudentTableModel();
        JTable jTable = new JTable(roomForStudentTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(studentPanel());
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.add(panel);
        return panel;
    }

    /**
     * 学生点击‘申请自习室’时显示的面板
     *
     * @return
     */
    private JPanel applyStudyRoom() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        JPanel panel2 = new JPanel(new GridLayout(2, 2, 10, 10));
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        JLabel studyRoomIdLabel = new JLabel("     自习室编号:");
        studyRoomIdLabel.setFont(new Font("宋体", Font.BOLD, 14));
        JTextField jTextField = new JTextField();
        JButton confirmButton = new JButton("申请");

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("            申请自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(studentPanel());
                frame.setSize(800, 400);
                frame.revalidate();
            }
        });
        confirmButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(UserClientService.isServerClose()){
                    JOptionPane.showMessageDialog(frame, "与服务器断开连接！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                RightToUseStudyRoom rightToUseStudyRoom = UserClientService.getRightByStuIdForStudent();
                if (rightToUseStudyRoom != null) {
                    //System.out.println(">> 您已经申请到了自习室！（每人同一时间只可拥有一个自习室使用权）");
                    JOptionPane.showMessageDialog(frame, "每人同一时间只可拥有一个自习室使用权，您已经申请到了自习室，请先归还当前拥有的自习室使用权方可再次申请！", "错误", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String studyRoomId = jTextField.getText();
                StudyRoom studyRoom = UserClientService.getStudyRoomByIdForStudent(studyRoomId);
                if (studyRoom == null) {
                    //System.out.println(">> 编号为[" + studyRoomId + "]的自习室并不存在！");
                    JOptionPane.showMessageDialog(frame, "编号为[" + studyRoomId + "]的自习室并不存在！", "警告", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                int remainingSeats = studyRoom.getRemainingSeats();
                if (remainingSeats <= 0) {
                    //System.out.println(">> 编号为[" + studyRoomId + "]的自习室已经没有空闲座位！");
                    JOptionPane.showMessageDialog(frame, "编号为[ " + studyRoomId + " ]的自习室已经没有空闲座位！", "警告", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                int option = JOptionPane.showConfirmDialog(frame, "是否确认申请编号为[ " + studyRoomId + " ]的自习室?", "确认",
                        JOptionPane.YES_NO_CANCEL_OPTION);

                if (option == JOptionPane.YES_OPTION) {
                    //System.out.println("确认添加");
                    if (UserClientService.applyStudyRoom(remainingSeats, studyRoomId)) {
                        //System.out.println(">> 申请成功！");
                        JOptionPane.showMessageDialog(frame, "您已经成功申请编号为[ " + studyRoomId + " ]的自习室！", "申请成功", JOptionPane.PLAIN_MESSAGE);

                    } else {
                        //System.out.println(">> 申请失败！");
                        JOptionPane.showMessageDialog(frame, "很遗憾，您没能成功申请编号为[ " + studyRoomId + " ]的自习室。", "申请失败", JOptionPane.PLAIN_MESSAGE);
                    }
                } else if (option == JOptionPane.CANCEL_OPTION) {
                    //System.out.println("取消添加");
                } else if (option == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("关闭添加");
                } else if (option == JOptionPane.NO_OPTION) {
                    //System.out.println("否添加");
                }

            }
        });

        //添加到面板上
        panel2.add(studyRoomIdLabel);
        panel2.add(jTextField);
        panel2.add(new JLabel());
        panel2.add(confirmButton);
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(panel2, BorderLayout.CENTER);

        frame.add(panel);
        frame.setSize(400, 250);
        return panel;
    }

    /**
     * 学生点击‘查询空闲自习室’时显示的面板
     *
     * @return
     */
    private JPanel listAllStudyRoom() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        StudyRoomForStudentTableModel studyRoomForStudentTableModel = new StudyRoomForStudentTableModel();

        JButton function1Button = new JButton("返回");
        JLabel label = new JLabel("                         查询空闲自习室");
        label.setFont(new Font("宋体", Font.BOLD, 22));
        JTable jTable = new JTable(studyRoomForStudentTableModel);
        JScrollPane jScrollPane = new JScrollPane(jTable);

        // 在这里添加按钮的功能
        function1Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setContentPane(studentPanel());
                frame.revalidate();
            }
        });

        //添加到面板上
        panel.add(function1Button, BorderLayout.WEST);
        panel.add(label, BorderLayout.NORTH);
        panel.add(jScrollPane, BorderLayout.CENTER);

        frame.add(panel);
        return panel;
    }

    public class StudyRoomForStudentTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"自习室编号", "自习室地址", "自习室名字", "总座位数", "剩余座位数"};
        public List<StudyRoom> studyRooms = UserClientService.studyRoomListForStudent();

        @Override
        public int getRowCount() {
            return studyRooms.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            StudyRoom studyRoom = studyRooms.get(rowIndex);
            if (columnIndex == 0) {
                return studyRoom.getStudyRoomId();
            } else if (columnIndex == 1) {
                return studyRoom.getAddress();
            } else if (columnIndex == 2) {
                return studyRoom.getRoomName();
            } else if (columnIndex == 3) {
                return studyRoom.getSeats();
            } else if (columnIndex == 4) {
                return studyRoom.getRemainingSeats();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }

    public class RoomForStudentTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"学号", "自习室编号", "自习室地址", "自习室名字", "申请时间"};
        public RoomForStudent roomForStudent = UserClientService.getAppliedStudyRoom();

        @Override
        public int getRowCount() {
            return 1;
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                return roomForStudent.getStudentId();
            } else if (columnIndex == 1) {
                return roomForStudent.getStudyRoomId();
            } else if (columnIndex == 2) {
                return roomForStudent.getAddress();
            } else if (columnIndex == 3) {
                return roomForStudent.getRoomName();
            } else if (columnIndex == 4) {
                return roomForStudent.getApplicationTime();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }

    public class HistoryForStudentTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"学号", "自习室编号", "自习室地址", "自习室名字", "申请时间", "结束使用时间"};
        public List<HistoryForStudent> historyForStudents = UserClientService.getHistoryForStudentByStudentId();

        @Override
        public int getRowCount() {
            return historyForStudents.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            HistoryForStudent historyForStudent = historyForStudents.get(rowIndex);
            if (columnIndex == 1) {
                return historyForStudent.getStudyRoomId();
            } else if (columnIndex == 0) {
                return historyForStudent.getStudentId();
            } else if (columnIndex == 2) {
                return historyForStudent.getAddress();
            } else if (columnIndex == 3) {
                return historyForStudent.getRoomName();
            } else if (columnIndex == 4) {
                return historyForStudent.getApplicationTime();
            } else if (columnIndex == 5) {
                return historyForStudent.getDiscontinuingUseTime();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }

    public class RightRecordTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"使用权编号", "学号", "学生姓名", "自习室编号", "自习室地址", "自习室名字", "申请时间"};
        public List<RightRecord> rightRecords = UserClientService.rightList();

        @Override
        public int getRowCount() {
            return rightRecords.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            RightRecord rightRecord = rightRecords.get(rowIndex);
            if (columnIndex == 0) {
                return rightRecord.getRightId();
            } else if (columnIndex == 1) {
                return rightRecord.getStudentId();
            } else if (columnIndex == 2) {
                return rightRecord.getStudentName();
            } else if (columnIndex == 3) {
                return rightRecord.getStudyRoomId();
            } else if (columnIndex == 4) {
                return rightRecord.getAddress();
            } else if (columnIndex == 5) {
                return rightRecord.getRoomName();
            } else if (columnIndex == 6) {
                return rightRecord.getApplicationTime();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }

    public class RevokeRecordForAdminTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"使用权编号", "学号", "学生姓名", "管理员编号", "管理员姓名", "自习室编号", "自习室地址", "自习室名字", "撤销时间", "撤销原因"};
        public List<RevokeRecordForAdmin> revokeRecordForAdmins = UserClientService.revokeRecordForAdminList();

        @Override
        public int getRowCount() {
            return revokeRecordForAdmins.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            RevokeRecordForAdmin revokeRecordForAdmin = revokeRecordForAdmins.get(rowIndex);
            if (columnIndex == 0) {
                return revokeRecordForAdmin.getRightId();
            } else if (columnIndex == 1) {
                return revokeRecordForAdmin.getStudentId();
            } else if (columnIndex == 2) {
                return revokeRecordForAdmin.getStudentName();
            } else if (columnIndex == 3) {
                return revokeRecordForAdmin.getAdministratorId();
            } else if (columnIndex == 4) {
                return revokeRecordForAdmin.getAdministratorName();
            } else if (columnIndex == 5) {
                return revokeRecordForAdmin.getStudyRoomId();
            } else if (columnIndex == 6) {
                return revokeRecordForAdmin.getAddress();
            } else if (columnIndex == 7) {
                return revokeRecordForAdmin.getRoomName();
            } else if (columnIndex == 8) {
                return revokeRecordForAdmin.getRevokeTime();
            } else if (columnIndex == 9) {
                return revokeRecordForAdmin.getRevokeReason();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }

    public class StudentTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"学号", "学生姓名", "密码（已使用MD5进行加密）", "专业", "性别", "年龄", "电话号码"};
        public List<Student> students = UserClientService.studentList();

        @Override
        public int getRowCount() {
            return students.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            Student student = students.get(rowIndex);
            if (columnIndex == 0) {
                return student.getStudentId();
            } else if (columnIndex == 1) {
                return student.getStudentName();
            } else if (columnIndex == 2) {
                return student.getPassword();
            } else if (columnIndex == 3) {
                return student.getMajor();
            } else if (columnIndex == 4) {
                return student.getGender();
            } else if (columnIndex == 5) {
                return student.getAge();
            } else if (columnIndex == 6) {
                return student.getTelephone();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }

    public class StudyRoomForAdministratorTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"自习室编号", "自习室地址", "自习室名字", "总座位数", "剩余座位数"};
        public List<StudyRoom> studyRooms = UserClientService.studyRoomListForAdministrator();

        @Override
        public int getRowCount() {
            return studyRooms.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            StudyRoom studyRoom = studyRooms.get(rowIndex);
            if (columnIndex == 0) {
                return studyRoom.getStudyRoomId();
            } else if (columnIndex == 1) {
                return studyRoom.getAddress();
            } else if (columnIndex == 2) {
                return studyRoom.getRoomName();
            } else if (columnIndex == 3) {
                return studyRoom.getSeats();
            } else if (columnIndex == 4) {
                return studyRoom.getRemainingSeats();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }
    public class HistoryOfRoomUsageTableModel extends AbstractTableModel {
        String[] columnNames = new String[]{"学号", "学生姓名", "自习室编号", "自习室地址", "自习室名字", "申请时间", "结束使用时间"};
        public List<HistoryOfRoomUsage> historyOfRoomUsages = UserClientService.historyOfRoomUsageList();

        @Override
        public int getRowCount() {
            return historyOfRoomUsages.size();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            HistoryOfRoomUsage historyOfRoomUsage = historyOfRoomUsages.get(rowIndex);
            if (columnIndex == 0) {
                return historyOfRoomUsage.getStudentId();
            } else if (columnIndex == 1) {
                return historyOfRoomUsage.getStudentName();
            } else if (columnIndex == 2) {
                return historyOfRoomUsage.getStudyRoomId();
            } else if (columnIndex == 3) {
                return historyOfRoomUsage.getAddress();
            } else if (columnIndex == 4) {
                return historyOfRoomUsage.getRoomName();
            } else if (columnIndex == 5) {
                return historyOfRoomUsage.getApplicationTime();
            } else if (columnIndex == 6) {
                return historyOfRoomUsage.getDiscontinuingUseTime();
            } else {
                return null;
            }
        }

        @Override
        public String getColumnName(int columnIndex) {
            // TODO Auto-generated method stub
            return columnNames[columnIndex];
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

    }
}

